﻿<%@ Application Language="C#" %>

<script runat="server">
    
    void Application_Start(object sender, EventArgs e) 
    {
        //Load logging configuration file
        log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "log.config")));

        //On load, check that System has been validated, all files are in place etc
        Application.Lock();
        Application["validated"] = false;
        Application.Lock();
        
        bool result = Symplectic.Spark.ValidateConfiguration.Check();

        Application.Lock();
        Application["validated"] = result;
        Application.Lock();
        
        
    }

    void Application_BeginRequest(Object sender, EventArgs e)
    {
        //If the system hasn't been validated successfully, then re-validate
        if (Application["validated"] == null || (!(bool)Application["validated"]))
        {
            bool result = Symplectic.Spark.ValidateConfiguration.Check();
            
            Application.Lock();
            Application["validated"] = result;
            Application.Lock();
        }
    }
        
       
</script>
